package br.unirio.ticketnator.action;

import br.unirio.ticketnator.dao.DAOFactory;
import br.unirio.ticketnator.dao.LoginDAO;
import org.apache.struts2.dispatcher.SessionMap;
import org.apache.struts2.interceptor.SessionAware;
import java.util.Map;
//import org.hibernate.validator.constraints.Email;

public class Login implements SessionAware {

    private String username, password;
    SessionMap<String, String> request;

    private static final long serialVersionUID = 1L;

    public String getUsername() {
        return username;

    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String execute() {
        if(LoginDAO.Validate(username,password)){
            request.put("usuario", username);
            return "success";
        }
        return "error";

    }

    @Override
    public void setSession(Map map) {
        request = (SessionMap) map;
    }
    public String logged(){
        return request.get("usuario") != null ? request.get("usuario") : "";
    }
    public String logout() {
        request.invalidate();
        return "success";
    }
}
